﻿using FantomNext.Controls;
using FantomNext.Helpers;
using FantomNext.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FantomNext.Factories
{
    /// <summary>
    /// 创建FantomShape的工厂，所有的创建都会走这里。
    /// </summary>
    public class FantomShapeFactory
    {
        /// <summary>
        /// 可以创建的类型，这里支持使用 FactoryType.PresetShape 或者使用 FactoryType.TextBox
        /// </summary>
        public static class FactoryType
        {
            public const string PresetShape = "PresetShape";
            public const string TextBox = "TextBox";
        }

        /// <summary>
        /// 创建一个名称随机的可视化图形控件。
        /// </summary>
        /// <param name="type">请在<see cref="FactoryType"/>中选择<see cref="FactoryType.TextBox"/>或者<see cref="FactoryType.PresetShape"/>填入。</param>
        /// <returns></returns>
        public FantomShape Create(string type)
        {
            return Create(type, RandomHelper.NewId());
        }

        /// <summary>
        /// 指定类型和 id 进行可视化图形控件的创建。
        /// </summary>
        /// <param name="type">请在<see cref="FactoryType"/>中选择<see cref="FactoryType.TextBox"/>或者<see cref="FactoryType.PresetShape"/>填入。</param>
        /// <param name="id">图形的 id，一般和<see cref="Shape.Id"/> 匹配对应一致。</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        private FantomShape Create(string type, string id)
        {
            if (type == FactoryType.PresetShape) return new FantomShape(id);
            if (type == FactoryType.TextBox) return new FantomTextBox(id);
            throw new NotImplementedException();
        }

        /// <summary>
        /// 从 <see cref="Shape"/> 对象创建可视化图形控件。
        /// </summary>
        /// <param name="shape"> 来自场景数据信息的图形对象。 </param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public FantomShape Create(Shape shape)
        {
            if (shape.ShapeType == ShapeType.PresetShape) return Create(FactoryType.PresetShape, shape.Id);
            if (shape.ShapeType == ShapeType.Text) return Create(FactoryType.TextBox, shape.Id);
            throw new NotImplementedException();
        }
    }
}
